// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.util.map;

import zombie.util.hash.DefaultIntHashFunction;

public abstract class AbstractIntKeyMap<V> implements IntKeyMap<V> {
    protected AbstractIntKeyMap() {
    }

    @Override
    public void clear() {
        IntKeyMapIterator intKeyMapIterator = this.entries();

        while (intKeyMapIterator.hasNext()) {
            intKeyMapIterator.next();
            intKeyMapIterator.remove();
        }
    }

    @Override
    public V remove(int _int) {
        IntKeyMapIterator intKeyMapIterator = this.entries();

        while (intKeyMapIterator.hasNext()) {
            intKeyMapIterator.next();
            if (intKeyMapIterator.getKey() == _int) {
                Object object = intKeyMapIterator.getValue();
                intKeyMapIterator.remove();
                return (V)object;
            }
        }

        return null;
    }

    @Override
    public void putAll(IntKeyMap<V> map) {
        IntKeyMapIterator intKeyMapIterator = map.entries();

        while (intKeyMapIterator.hasNext()) {
            intKeyMapIterator.next();
            this.put(intKeyMapIterator.getKey(), (V)intKeyMapIterator.getValue());
        }
    }

    @Override
    public boolean containsKey(int key) {
        IntKeyMapIterator intKeyMapIterator = this.entries();

        while (intKeyMapIterator.hasNext()) {
            intKeyMapIterator.next();
            if (intKeyMapIterator.getKey() == key) {
                return true;
            }
        }

        return false;
    }

    @Override
    public V get(int _int) {
        IntKeyMapIterator intKeyMapIterator = this.entries();

        while (intKeyMapIterator.hasNext()) {
            intKeyMapIterator.next();
            if (intKeyMapIterator.getKey() == _int) {
                return (V)intKeyMapIterator.getValue();
            }
        }

        return null;
    }

    @Override
    public boolean containsValue(Object value) {
        IntKeyMapIterator intKeyMapIterator = this.entries();
        if (value == null) {
            while (intKeyMapIterator.hasNext()) {
                intKeyMapIterator.next();
                if (value == null) {
                    return true;
                }
            }
        } else {
            while (intKeyMapIterator.hasNext()) {
                intKeyMapIterator.next();
                if (value.equals(intKeyMapIterator.getValue())) {
                    return true;
                }
            }
        }

        return false;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof IntKeyMap intKeyMap)) {
            return false;
        } else if (this.size() != intKeyMap.size()) {
            return false;
        } else {
            IntKeyMapIterator intKeyMapIterator = this.entries();

            while (intKeyMapIterator.hasNext()) {
                intKeyMapIterator.next();
                int _int = intKeyMapIterator.getKey();
                Object object = intKeyMapIterator.getValue();
                if (object == null) {
                    if (intKeyMap.get(_int) != null) {
                        return false;
                    }

                    if (!intKeyMap.containsKey(_int)) {
                        return false;
                    }
                } else if (!object.equals(intKeyMap.get(_int))) {
                    return false;
                }
            }

            return true;
        }
    }

    @Override
    public int hashCode() {
        int _int = 0;

        for (IntKeyMapIterator intKeyMapIterator = this.entries();
            intKeyMapIterator.hasNext();
            _int += DefaultIntHashFunction.INSTANCE.hash(intKeyMapIterator.getKey()) ^ intKeyMapIterator.getValue().hashCode()
        ) {
            intKeyMapIterator.next();
        }

        return _int;
    }

    @Override
    public boolean isEmpty() {
        return this.size() == 0;
    }

    @Override
    public int size() {
        int _int = 0;

        for (IntKeyMapIterator intKeyMapIterator = this.entries(); intKeyMapIterator.hasNext(); _int++) {
            intKeyMapIterator.next();
        }

        return _int;
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append('[');
        IntKeyMapIterator intKeyMapIterator = this.entries();

        while (intKeyMapIterator.hasNext()) {
            if (stringBuilder.length() > 1) {
                stringBuilder.append(',');
            }

            intKeyMapIterator.next();
            stringBuilder.append(String.valueOf(intKeyMapIterator.getKey()));
            stringBuilder.append("->");
            stringBuilder.append(String.valueOf(intKeyMapIterator.getValue()));
        }

        stringBuilder.append(']');
        return stringBuilder.toString();
    }

    public void trimToSize() {
    }
}
